<?php

	class Db {
		
		private $conn;

		//	建立连接
		public function __construct() {
			
			$this->conn = mysql_connect('localhost', 'root', 'zpc456..');
			
			if(!mysql_query('set names utf8')) {
				
				$err = '数据库编码设置失败' . mysql_error();
				
				return $err;
				
			}
			
			if(!$this->conn) {
				
				$err = '数据库连接失败' . mysql_error();
				
				return $err;
				
			}
			
			mysql_select_db('resume', $this->conn) or die('选择失败<br/>'.mysql_error());
			
			return $this->conn;
		}

		public function connect() {

			if(false !== $this->conn) {

                return $this->conn;

            }

            return false;

		}
		
		
		public function myQuery($sql) {
			
			if(!empty($sql)) {
				
				$res = mysql_query($sql, $this->conn);
				
				$i = 0;
				
				while($tmp = mysql_fetch_assoc($res)) {
					
					$result[$i++] = $tmp;
					
				}
				
				return $result;
				
			}
			
		}
		
		
		//	断开连接
		public function dbClose() {
			
			mysql_close($this->conn) or die('关闭失败<br/>'.mysql_error());
			
		}
		
		
		//	执行 Sql 语句
		public function sqlQuery($sql) {
			
			$res = mysql_query($sql, $this->conn);
			
			if(false !== $res) {

				return $res;
			
			}
			
			return false;
			
		}

	}
?>



















